# -*- coding: utf-8 -*-
import xadmin
from xadmin import views
from xadmin.plugins.auth import UserAdmin
from django.contrib.auth import get_user_model

# xadmin全局配置

from good.models import *
from user.models import *
from invoice.models import *
from organization.models import *
from label.models import *
from page.models import *
from xadmin.models import UserSettings, Log, UserWidget,Bookmark
from django.contrib.auth.models import Group, Permission

@xadmin.sites.register(views.BaseAdminView)
class BaseSetting(object):
    # UI主题
    enable_themes = True
    # use_bootswatch = True


# xadmin.site.register(views.BaseAdminView,BaseSetting)


@xadmin.sites.register(views.CommAdminView)
class GlobalSettings(object):
    site_title = "Retail Management Information System"
    site_footer = "RedFoxatAsleep"
    menu_style = "accordion"
    apps_icons = {"good": "fa fa-thermometer-1"}

    def custom_site_menu(self):
        return [
            {
                'title': u'商品管理',
                'icon': 'fa fa-barcode',
                'menus': (
                    {
                        'title': u'商品',
                        'icon': 'fa fa-dot-circle-o',
                        'url': self.get_model_url(Good, 'changelist'),
                        'perm': self.get_model_perm(Good, 'view'),
                    },
                    {
                        'title': u'商品图片',
                        'icon': 'fa fa-file-image-o',
                        'url': self.get_model_url(GoodMultimedia, 'changelist'),
                        'perm': self.get_model_perm(GoodMultimedia, 'view'),
                     },
                )
            },
            {
                'title': u'订单管理',
                'icon': 'fa fa-file-text-o',
                'menus': (
                    {
                        'title': u'销售单据',
                        'icon': 'fa fa-dot-circle-o',
                        'url': self.get_model_url(Sale, 'changelist'),
                        'perm': self.get_model_perm(Sale, 'view'),
                    },
                    {
                        'title': u'销售单据商品清单',
                        'icon': 'fa fa-dot-circle-o',
                        'url': self.get_model_url(GoodInSale, 'changelist'),
                        'perm': self.get_model_perm(GoodInSale, 'view'),
                     },
                    # {
                    #     'title': u'交易评价',
                    #     'icon': 'fa fa-dot-circle-o',
                    #     'url': self.get_model_url(SaleComment, 'changelist'),
                    #     'perm': self.get_model_perm(SaleComment, 'view'),
                    #  },
                    # {
                    #     'title': u'商品评价',
                    #     'icon': 'fa fa-dot-circle-o',
                    #     'url': self.get_model_url(GoodComment, 'changelist'),
                    #     'perm': self.get_model_perm(GoodComment, 'view'),
                    #  },
                    {
                        'title': u'进货单据',
                        'icon': 'fa fa-dot-circle-o',
                        'url': self.get_model_url(Purchase, 'changelist'),
                        'perm': self.get_model_perm(Purchase, 'view'),
                     },
                    {
                        'title': u'进货单据商品清单',
                        'icon': 'fa fa-dot-circle-o',
                        'url': self.get_model_url(GoodInPurchase, 'changelist'),
                        'perm': self.get_model_perm(GoodInPurchase, 'view'),
                     },
                    {
                        'title': u'退货单据',
                        'icon': 'fa fa-dot-circle-o',
                        'perm': self.get_model_perm(Refund, 'view'),
                        'url': self.get_model_url(Refund, 'changelist'),
                     },
                    {
                        'title': u'其他费用',
                        'icon': 'fa fa-dot-circle-o',
                        'perm': self.get_model_perm(Expense, 'view'),
                        'url': self.get_model_url(Expense, 'changelist'),
                     },
                )
            },
            {
                'title': u'店铺管理',
                'icon': 'fa fa-bank',
                'menus': (
                    {
                        'title': u'店铺',
                        'icon': 'fa fa-home',
                        'url': self.get_model_url(Store, 'changelist'),
                        'perm': self.get_model_perm(Store, 'view'),
                    },
                )
            },
            {
                'title': u'标签管理',
                'icon': 'fa fa-tags',
                'menus': (
                    {
                        'title': u'标签目标',
                        'icon': 'fa fa-dot-circle-o',
                        'url': self.get_model_url(LabelTarget, 'changelist'),
                        'perm': self.get_model_perm(LabelTarget, 'view'),
                    },
                    {
                        'title': u'标系系列',
                        'icon': 'fa fa-reorder',
                        'url': self.get_model_url(LabelSeries, 'changelist'),
                        'perm': self.get_model_perm(LabelSeries, 'view'),
                    },
                    {
                        'title': u'标签',
                        'icon': 'fa fa-tag',
                        'url': self.get_model_url(Label, 'changelist'),
                        'perm': self.get_model_perm(Label, 'view'),
                    },
                    {
                        'title': u'商品标签',
                        'icon': 'fa fa-link',
                        'url': self.get_model_url(LabelStickGood, 'changelist'),
                        'perm': self.get_model_perm(LabelStickGood, 'view'),
                    },
                )
            },
            {
                'title': u'数据统计',
                'icon': 'fa fa-area-chart',
                'menus': (
                    {
                        'title': u'销售流水',
                        'icon': 'fa fa-bar-chart',
                        'url': self.get_model_url(SaleAlongTime, 'changelist'),
                        'perm': self.get_model_perm(SaleAlongTime, 'view'),
                    },
                    {
                        'title': u'销售价格',
                        'icon': 'fa fa-bar-chart-o',
                        'url': self.get_model_url(SalePriceIO, 'changelist'),
                        'perm': self.get_model_perm(SalePriceIO, 'view'),
                    },
                    {
                        'title': u'销售分布',
                        'icon': 'fa fa-bar-chart',
                        'url': self.get_model_url(SalePeriod, 'changelist'),
                        'perm': self.get_model_perm(SalePeriod, 'view'),
                    },
                    {
                        'title': u'销售分类',
                        'icon': 'fa fa-pie-chart',
                        'url': self.get_model_url(SaleLabel, 'changelist'),
                        'perm': self.get_model_perm(SaleLabel, 'view'),
                    },
                    {
                        'title': u'库存状况',
                        'icon': 'fa fa-line-chart',
                        'url': self.get_model_url(Inventory, 'changelist'),
                        'perm': self.get_model_perm(Inventory, 'view'),
                    },
                    {
                        'title': u'店员绩效',
                        'icon': 'fa fa-bar-chart',
                        'url': self.get_model_url(ClerkPerformance, 'changelist'),
                        'perm': self.get_model_perm(ClerkPerformance, 'view'),
                    },
                    {
                        'title': u'其他费用',
                        'icon': 'fa fa-pie-chart',
                        'url': self.get_model_url(ExpenseAlongTime, 'changelist'),
                        'perm': self.get_model_perm(ExpenseAlongTime, 'view'),
                    },
                )
            },
            {
                'title': u'用户管理',
                'icon': 'fa fa-user-circle',
                'menus': (
                    # {
                    #     'title': u'用户',
                    #     'icon': 'fa fa-user-o',
                    #     'url': self.get_model_url(UserProfile, 'changelist'),
                    #     'perm': self.get_model_perm(UserProfile, 'view'),
                    # },
                    {
                        'title': u'系统管理员',
                        'icon': 'fa fa-user-o',
                        'url': self.get_model_url(Administrator, 'changelist'),
                        'perm': self.get_model_perm(Administrator, 'view'),
                    },
                    {
                        'title': u'店员',
                        'icon': 'fa fa-user-o',
                        'url': self.get_model_url(Clerk, 'changelist'),
                        'perm': self.get_model_perm(Clerk, 'view'),
                    },
                    {
                        'title': u'顾客',
                        'icon': 'fa fa-user-o',
                        'url': self.get_model_url(Customer, 'changelist'),
                        'perm': self.get_model_perm(Customer, 'view'),
                    },
                )
            },
            {
                'title': u'管理',
                'icon': 'fa fa-cogs',
                'menus': (
                    {
                        'title': u'用户设置',
                        'icon': 'fa fa-cog',
                        'url': self.get_model_url(UserSettings, 'changelist'),
                        'perm': self.get_model_perm(UserSettings, 'view'),
                    },
                    {
                        'title': u'日志记录',
                        'icon': 'fa fa-cog',
                        'url': self.get_model_url(Log, 'changelist'),
                        'perm': self.get_model_perm(Log, 'view'),
                    },
                    {
                        'title': u'用户组件',
                        'icon': 'fa fa-cog',
                        'url': self.get_model_url(UserWidget, 'changelist'),
                        'perm': self.get_model_perm(UserWidget, 'view'),
                    },
                    {
                        'title': u'书签',
                        'icon': 'fa fa-cog',
                        'url': self.get_model_url(Bookmark, 'changelist'),
                        'perm': self.get_model_perm(Bookmark, 'view'),
                    },
                )
            },
            {
                'title': u'认证和授权',
                'icon': 'fa fa-group',
                'menus': (
                    {
                        'title': u'组',
                        'icon': 'fa fa-group',
                        'url': self.get_model_url(Group, 'changelist'),
                        'perm': self.get_model_perm(Group, 'view'),
                    },
                    {
                        'title': u'权限',
                        'icon': 'fa fa-lock',
                        'url': self.get_model_url(Permission, 'changelist'),
                        'perm': self.get_model_perm(Permission, 'view'),
                    },
                )
            },
            {
                'title': u'外部链接',
                'icon': 'fa fa-external-link',
                # 'perm': self.get_model_perm(UserProfile, 'view'),
                'menus': (
                    {
                        'title': u'扩展用页面',
                        'icon': 'fa fa-external-link-square',
                        'url': 'http://rmis.redfoxatasleep.top',
                    },
                    {
                        'title': u'优衣库',
                        'icon': 'fa fa-external-link-square',
                        'url': 'https://www.uniqlo.cn',
                    },
                    {
                        'title': u'毕业设计演示大纲',
                        'icon': 'fa fa-external-link-square',
                        'url': 'http://redfoxatasleep.top/static/speech.html',
                    },
                    # {
                    #     'title': u'首页',
                    #     'icon': 'fa fa-external-link-square',
                    #     'url': self.get_admin_url('index'),
                    #     # 这样该菜单会一直展开
                    # },
                )
            },
        ]

    def get_site_menu(self):
        menus = []
        menus.extend(self.custom_site_menu())
        return menus

    # def get_nav_menu(self):
    #     # 仅返回自己描述的菜单栏，覆盖源码不合并其他未描述的菜单
    #     site_menu = list(self.get_site_menu() or [])
    #     return site_menu


@xadmin.sites.register(views.website.IndexView)
class MainDashboard(object):
    # widgets = [
    #     [
    #         {"type": "html", "title": "Welcome",
    #          "content": "<h3> 欢迎使用店铺管理信息系统</h3><p>Contact: <br/>QQ : 1400556159<br/>WeChat : xiluoyuechen</p>"},
    #         # {"type": "chart", "model": "app.accessrecord", "chart": "user_count",
    #         #  "params": {"_p_date__gte": "2013-01-08", "p": 1, "_p_date__lt": "2013-01-29"}},
    #         {"type": "list", "model": UserProfile, "params": {"o": "-joined"}},
    #         {"title": "Good List", "model": "xadmin.userwidget"},
    #     ],
    #     [
    #         {"type": "qbutton", "title": "Quick Start",
    #          "btns": [{"model": Purchase}, {"model": Sale}, {"title": "Google", "url": "http://www.google.com"}]},
    #         {"type": "addform", "model": Good},
    #     ]
    # ]
    pass


# xadmin.site.register(views.CommAdminView,GlobalSettings)

# from xadmin.plugins.auth import Group, GroupAdmin
# from django.contrib.auth.models import Group, Permission
# 已经在xadmin.plugins.auth中注册register过了如果需要重新注册需要先注销unregister

